//package keeto.com.vn.classfied.model;
//
//import java.util.HashMap;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//import keeto.com.vn.classified.ui.R;
//
//import android.content.Context;
//import android.text.SpannableStringBuilder;
//import android.text.Spanned;
//import android.text.style.ImageSpan;
//
//
//public class SmileyParser {
//	private static SmileyParser sInstance;
//
//	public static SmileyParser getInstance(Context context) {
//		if (sInstance == null) {
//			sInstance = new SmileyParser(context);
//		}
//		return sInstance;
//	}
//
//	private final Context mContext;
//	private final String[] mSmileyTexts;
//	private final Pattern mPattern;
//	private final HashMap<String, Integer> mSmileyToRes;
//
//	private SmileyParser(Context context) {
//		mContext = context;
//		mSmileyTexts = mContext.getResources().getStringArray(
//				DEFAULT_SMILEY_TEXTS);
//		mSmileyToRes = buildSmileyToRes();
//		mPattern = buildPattern();
//	}
//
//	public static int DEFAULT_SMILEY_TEXTS = R.array.default_smiley_texts;
//
//	public static final int[] STICKER_ICONS = { R.drawable.bear1,
//			R.drawable.bear2, R.drawable.bear3, R.drawable.bear4,
//			R.drawable.bear5, R.drawable.bear6, R.drawable.bear7,
//			R.drawable.bear8, R.drawable.bear9, R.drawable.bear10,
//			R.drawable.bear11, R.drawable.bear12, R.drawable.bear13,
//			R.drawable.bear14, R.drawable.bear15, R.drawable.bear16,
//			R.drawable.bear17, R.drawable.bear18, R.drawable.bear19,
//			R.drawable.bear20, R.drawable.bear21 };
//
//	static class Smileys {
//
//		private static final int[] sIconIds = { 
//			R.drawable.emoti_lol,
//			R.drawable.emoti_money_in_eyes,
//			R.drawable.emoti_fall_in_love,
//			R.drawable.emoti_big_cry,
//			R.drawable.emoti_laugh,
//			R.drawable.emoti_faint,
//			R.drawable.emoti_delicious,
//			R.drawable.emoti_plaster_on_face,
//			R.drawable.emoti_sissy_maho,
//			R.drawable.emoti_angry,
//			R.drawable.emoti_whistling,
//			R.drawable.emoti_sick,
//			R.drawable.emoti_coolman,
//			R.drawable.emoti_bored,
//			R.drawable.emoti_wow,
//			R.drawable.emoti_dizzy,
//			R.drawable.emoti_cry,
//			R.drawable.emoti_zip_mouth,
//			R.drawable.emoti_sleepy,
//			R.drawable.emoti_hate,
//			R.drawable.emoti_boy_with_cap,
//			R.drawable.emoti_android,
//			R.drawable.emoti_love,
//			R.drawable.emoti_half_broken_heart,
//			R.drawable.emoti_broken_heart,
//			R.drawable.emoti_ghost,
//			R.drawable.emoti_indonesian_flag,
//			R.drawable.emoti_gift,
//			R.drawable.emoti_music,
//			R.drawable.emoti_rainbow,
//			R.drawable.emoti_coffee,
//			R.drawable.emoti_cake,
//			R.drawable.emoti_bulb,
//			R.drawable.emoti_star,
//			R.drawable.emoti_lightning,
//			R.drawable.emoti_stop,
//			R.drawable.emoti_shake_hands,
//
//		};
//
//		public static int getSmileyResource(int which) {
//			return sIconIds[which];
//		}
//
//		public static int[] getSmileyResources() {
//			return sIconIds;
//		}
//	}
//
//	public static final int[] DEFAULT_SMILEY_RES_IDS = Smileys
//			.getSmileyResources();
//
//	/**
//	 * Builds the hashtable we use for mapping the string version of a smiley
//	 * (e.g. ":-)") to a resource ID for the icon version.
//	 */
//	private HashMap<String, Integer> buildSmileyToRes() {
//		if (DEFAULT_SMILEY_RES_IDS.length != mSmileyTexts.length) {
//			// Throw an exception if someone updated DEFAULT_SMILEY_RES_IDS
//			// and failed to update arrays.xml
//			throw new IllegalStateException("Smiley resource ID/text mismatch");
//		}
//
//		HashMap<String, Integer> smileyToRes = new HashMap<String, Integer>(
//				mSmileyTexts.length);
//		for (int i = 0; i < mSmileyTexts.length; i++) {
//			smileyToRes.put(mSmileyTexts[i], DEFAULT_SMILEY_RES_IDS[i]);
//		}
//		return smileyToRes;
//	}
//
//	/**
//	 * Builds the regular expression we use to find smileys in
//	 * {@link #addSmileySpans}.
//	 */
//	private Pattern buildPattern() {
//		// Set the StringBuilder capacity with the assumption that the average
//		// smiley is 3 characters long.
//		StringBuilder patternString = new StringBuilder(mSmileyTexts.length * 3);
//
//		// Build a regex that looks like (:-)|:-(|...), but escaping the smilies
//		// properly so they will be interpreted literally by the regex matcher.
//		patternString.append('(');
//		for (String s : mSmileyTexts) {
//			patternString.append(Pattern.quote(s));
//			patternString.append('|');
//		}
//		// Replace the extra '|' with a ')'
//		patternString.replace(patternString.length() - 1,
//				patternString.length(), ")");
//
//		return Pattern.compile(patternString.toString());
//	}
//
//	/**
//	 * Adds ImageSpans to a CharSequence that replace textual emoticons such as
//	 * :-) with a graphical version.
//	 * 
//	 * @param text
//	 *            A CharSequence possibly containing emoticons
//	 * @return A CharSequence annotated with ImageSpans covering any recognized
//	 *         emoticons.
//	 */
//	public CharSequence parseToSmiley(CharSequence text) {
//		SpannableStringBuilder builder = new SpannableStringBuilder(text);
//
//		Matcher matcher = mPattern.matcher(text);
//		while (matcher.find()) {
//			int resId = mSmileyToRes.get(matcher.group());
//			builder.setSpan(new ImageSpan(mContext, resId), matcher.start(),
//					matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//		}
//		return builder;
//	}
//
//}
